<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
        <meta name="description" content="">
        <meta name="author" content="">

        <title>后台</title>

        <link href="__PUBLIC__/images/favicon.ico" rel="shortcut icon" />

        <!-- Bootstrap core CSS -->
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-theme.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/dashboard.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/icheck/all.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-datetimepicker.css" />
    </head>

    <body>

    <include file="Common/topNav" />

    <div class="container-fluid">
        <div class="row">
            <include file="Common/leftMenu" />
            <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
                <div class="cont-title clearfix">
                    <div class="title">出租列表</div>
                    <div class="btn-group">
                        <button class="btn" type="button" id="add_lease">添加</button>
                    </div>
                </div>
                <form class="jc-search form-inline searchForm" action="{:U('Admin/Rental/leaseList')}" method="post">
                    <div class="form-group">
                        <label>楼宇名称:</label>
                        <select class="form-control" name="house_id">
                            <option value="">全部</option>
                            <volist name="houseList" id="item">
                                <option <if condition="$houseId eq $item['id']">selected="selected"</if> value="{$item.id}">{$item.name}</option>
                            </volist>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>状态:</label>
                        <select class="form-control" name="audit">
                            <option value="-1">全部</option>
                            <option value="0" <if condition="$audit eq 0">selected</if>>待审核</option>
                            <option value="1" <if condition="$audit eq 1">selected</if>>已审核</option>
                            <option value="2" <if condition="$audit eq 2">selected</if>>未通过</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>发布时间:</label>
                        <div class='input-group date col-sm-7' id='datetimepicker'>
                            <input type='text' value="{$_REQUEST['create_time']}" name="create_time" class="form-control " data-date-format="yyyy-mm-dd" />
                            <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span></span>
                        </div>
                    </div>
                    <input class="btn" type="submit" value="查询" />
                </form>
                <div class="table-responsive">
                    <table class="table table-striped table-hover" id="tableData">
                        <thead>
                            <tr>
                            	<th>序号</th>
                                <th>楼宇名称</th>
                                <th>楼宇地址</th>
                                <th>房号</th>
                                <th>面积（㎡）</th>
                                <th>出租人</th>
                                <th>出租人电话</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        <empty name="leaseList['list']">
                        	<tr>
                        		<td colspan="10">没有相关记录</td>
                        	</tr>
                        </empty>
                        <foreach name="leaseList['list']" item="lease">
                            <tr>
                            	<td>{$key|getLineNum=$nowPage,$pageSize}</td>
                                <td>{$lease.house.name}</td>
                                <td>{$lease.house.position}</td>
                                <td>{$lease.room}</td>
                                <td>{$lease.area|number_format=2}</td>
                                <td>{$lease.contacts}</td>
                                <td>{$lease.contact_phone}</td>
                                <td>
                                    <if condition="$lease.audit eq 0">
                                        <span class="label label-warning">待审核</span>
                                    <elseif condition="$lease.audit eq 1" />
                                        <span class="label label-success">已审核</span>
                                    <else/>
                                        <span class="label label-danger">未通过</span>
                                    </if>
                                </td>
                                <td>
                                    <a thisId="{$lease.id}" href="javascript:void(0);" class="lease_detail">查看详情</a>
                                    | <a thisId="{$lease.id}" href="javascript:void(0);" class="lease_edit">修改</a>
                                    | <a thisId="{$lease.id}" href="javascript:void(0);" class="lease_del">删除</a>
                                    <if condition="$lease.audit eq 0">
                                        | <a thisId="{$lease.id}" href="javascript:void(0);" class="audit" >审核</a>
                                    </if>
                                </td>
                            </tr>
                        </foreach>    
                        </tbody>
                    </table>
                    <div class="page">
                    	{$leaseList.page}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <include file="Common/modalHtmls" />
    <script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/icheck.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#add_lease").bind("click",addLease);
            $("#tableData .lease_detail").click(function(){
                showDetail(this);
            });
            $("#tableData .lease_edit").click(function(){
                editLease(this);
            });
            $("#tableData .lease_del").click(function(){
                delLease(this);
            });
        });

    	function addLease(){
            common.loading('正在加载...');
    		common.htmlAjax("{:U('Admin/Rental/add')}", {}, function (html) {
                common.closeLoading();
                $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
            });
    	}

    	function showDetail(obj){
            common.loading('正在加载...');
    		var id = $(obj).attr("thisId");
    		common.htmlAjax("{:U('Admin/Rental/detail')}", {id:id}, function (html) {
                common.closeLoading();
                $("#commonModal").html(html).modal('toggle');
            });
    	}

        function editLease(obj){
            var id = $(obj).attr("thisId");
            common.loading('正在加载...');
            common.htmlAjax("{:U('Admin/Rental/add')}", {id:id}, function (html) {
                common.closeLoading();
                $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
            });
        }

        function delLease(obj){
            common.confirm("提示","确认删除该出租信息吗？",function(){
                var id = $(obj).attr("thisId");
                var param = {id:id};
                $.ajax({
                    url: "{:U('Admin/Rental/delete')}",
                    type: "post",
                    dataType: "json",
                    data: param,
                    success: function (data) {
                        if(data.status){
                            common.alert("提示","出租信息已成功删除!",function(){
                                common.reload();
                            });
                        }
                    }
                });
            });
        }


        $(".audit").click(function () {
            var id = $(this).attr("thisId");
            common.htmlAjax("{:U('Admin/Rental/leaseConfirm')}", {id: id}, function (html) {
                $("#commonModal").html(html).modal('toggle');
            })
        })
        $('#datetimepicker').datetimepicker({
            format: 'yyyy-mm-dd',
            language: 'ch',
            pickDate: true,
            pickTime: false,
            autoclose:true,
            minView:2,
            //pickerPosition:"bottom-left"
        });
    </script>
</body>
</html>
